package algorithm.leecode.permutation;

import java.util.*;

/**
 * @author bingo
 * @Description             太暴力解法
 * @Date 2018/8/31
 */
public class Demo {
    public static void main(String[] args) {
        int MAX_VALUE=10;
        int wt[] =  new int[]{1,2,3,4,5};
        Random random = new Random();
        Map<String,Integer> map =new HashMap<>();
        Set set = new HashSet();
        for(int i=0;i<10000;i++){
            int sum=0;
            StringBuffer stringBuffer = new StringBuffer();
            while (sum!=MAX_VALUE){
                int index = random.nextInt(wt.length);
                int item = wt[index];
                if(sum+item<=MAX_VALUE){
                    sum = sum+item;
                    stringBuffer.append(item);
                    }
            }
            set.add(stringBuffer.toString());
            if(map.containsKey(stringBuffer.toString())){
                int count  = map.get(stringBuffer.toString());
                 map.put(stringBuffer.toString(),++count);
            }
            else {
                map.put(stringBuffer.toString(),1);
            }
        }
        System.out.println("可能性:(set)"+set.size());
        Set<String> keySet = map.keySet();
        List<String> firstList  = new ArrayList<>();
        for(String str:keySet){
            System.out.println(str);
            if(str.startsWith("1")){
                firstList.add(str);
            }
        }
        System.out.println("所有为1开头的数据");
        for(int k = 0;k<firstList.size();k++){
            System.out.println(firstList.get(k));
        }
    }

}


